package progress.exa28_1.part4;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池ThreadPollExecutor学习
 * 通过ThreadPoolExecutor构造自定义线程池
 */
public class ThreadPoolExecutorStudy {

    /**
     * corePoolSize: 线程池核心数
     * maximumPoolSize: 线程池最大核心数: 只有当队列阻塞时才新建线程，但不能超过最大线程数
     * keepAliveTime: 线程的存活时间
     * TimeUnit:时间单位
     * 阻塞队列
     * 拒绝策略
     */
    public static final ThreadPoolExecutor POOL = new ThreadPoolExecutor(
            10,
           50,
            10,
            TimeUnit.SECONDS,
            new ArrayBlockingQueue<>(1),
            new ThreadPoolExecutor.CallerRunsPolicy());

    public static void showStatisticsInfo() {
        System.out.println("线程池统计->"
                        + "curPoolSize:{}, "+
                ThreadPoolExecutorStudy.POOL.getPoolSize());
    }
}
